import log from 'loglevel';
import { isBrowser } from 'umi';

log.setDefaultLevel(5);

const logReg = /log=([0,1,2,3,4,5]){1}$/g;

if (isBrowser()) {
  const logConfig = logReg.exec(window.location.search);
  if (logConfig && logConfig.length) {
    log.setLevel(parseInt(logConfig[1], 10) as log.LogLevelDesc);
  }
}

export function onRouteChange(props: IRouteChange) {
  log.info('onRouteChange', props);
}

interface IRouteChange {
  action: string;
  location: any;
  matchedRoutes: Array<{ match: any; route: any }>;
  routes: Array<{
    path: string;
    component: any;
    wrappers?: any;
    exact?: boolean;
    title?: string;
  }>;
}
